import 'package:flutter/material.dart';



class Test_CustomScrollViewPage extends StatefulWidget {
  const Test_CustomScrollViewPage({super.key});

  @override
  State<Test_CustomScrollViewPage> createState() =>
      _Test_CustomScrollViewPageState();
}

class _Test_CustomScrollViewPageState extends State<Test_CustomScrollViewPage> {
  var _switch = false;

  @override
  Widget build(BuildContext context) {
    // SystemChrome.setSystemUIOverlayStyle(
    //   const SystemUiOverlayStyle(
    //     statusBarColor: Colors.transparent, //背景颜色
    //     statusBarIconBrightness: Brightness.dark,  // Android 白色图标
    //     statusBarBrightness: Brightness.dark, // iOS 白色文字
    //   ),
    // );

    return Scaffold(
        // appBar: AppBar(title: const Text('Test_CustomScrollViewPage')),
        body: Stack(
      children: [
        buildTwoSliverList(context),
        // Positioned(
        //   top: 100,
        //   left: 0,
        //   right: 0,
        //   child:         ElevatedButton(
        //       onPressed: () {
        //         print('JtTag:触发点击${_switch}');
        //         setState(() {
        //           if (_switch) {
        //             SystemChrome.setSystemUIOverlayStyle(
        //               const SystemUiOverlayStyle(
        //                 statusBarColor: Colors.transparent, //背景颜色
        //                 statusBarIconBrightness: Brightness.dark,  // Android 白色图标
        //                 statusBarBrightness: Brightness.dark, // iOS 白色文字
        //               ),
        //             );
        //           } else {
        //             SystemChrome.setSystemUIOverlayStyle(
        //               const SystemUiOverlayStyle(
        //                 statusBarColor: Colors.transparent,
        //                 statusBarIconBrightness: Brightness.light,  // Android 黑色图标
        //                 statusBarBrightness: Brightness.light, // iOS 白色文字
        //               ),
        //             );
        //           }
        //           this._switch = !this._switch;
        //         });
        //       },
        //       child: Text('test'))
        //   ,
        // ),
      ],
    ));
  }

  // 不合适的场景
  Widget buildTwoListView() {
    var listView = ListView.builder(
      itemCount: 20,
      itemBuilder: (_, index) => ListTile(title: Text('$index')),
    );
    return Column(
      children: [
        Expanded(child: listView),
        Divider(color: Colors.grey),
        Expanded(child: listView),
      ],
    );
  }

  // 修改后的场景
  Widget buildTwoSliverList(BuildContext context) {
    // SliverFixedExtentList 是一个 Sliver，它可以生成高度相同的列表项。
    // 再次提醒，如果列表项高度相同，我们应该优先使用SliverFixedExtentList
    // 和 SliverPrototypeExtentList，如果不同，使用 SliverList.
    var listView = SliverFixedExtentList(
      itemExtent: 56, //列表项高度固定
      delegate: SliverChildBuilderDelegate(
        (_, index) => ListTile(title: Text('$index')),
        childCount: 10,
      ),
    );
    // 使用
    print('JtTag:Theme.of(context).brightness:${Theme.of(context).brightness}');
    return CustomScrollView(
      slivers: [
        // SliverAppBar(
        //   title: const Text('CustomScrollView 示例'),
        //   expandedHeight: 150,
        //   floating: true,
        //   flexibleSpace: const FlexibleSpaceBar(
        //     background: FlutterLogo(size: 150),
        //   ),
        // ),
        // listView,
        // listView,
        SliverAppBar(
          expandedHeight: 200,
          floating: true,
          flexibleSpace: const FlexibleSpaceBar(
            title: Text('Sliver 示例'),
          ),
        ),
        SliverList(
          delegate: SliverChildBuilderDelegate(
                (context, index) => ListTile(title: Text('Item $index')),
            childCount: 50,
          ),
        ),
        SliverGrid(
          delegate: SliverChildBuilderDelegate(
                (context, index) => Container(color: Colors.blue, child: Text("Grid $index")),
            childCount: 20,
          ),
          gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 2),
        ),
      ],
    );
  }
}
